/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package specifications;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;

/**
 *
 * @author Jason
 */
public class Directive implements YamlObject<Directive> {
    private int priority = 0;
    private String request;
    public static final Tag TAG = new Tag("!Directive");
    
    public Directive(){}
    public Directive(String request){this.request = request;}
    public Directive(String request, int priority){
        this.request = request;
        this.priority = priority;
    }
    
    @Override
    public void dump(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileWriter writer = new FileWriter(filename);
        writer.write(yaml.dumpAs(this, TAG, DumperOptions.FlowStyle.BLOCK));
        writer.close();
        //System.out.println(yaml.dumpAs(this, TAG, DumperOptions.FlowStyle.BLOCK));
    }

    @Override
    public Directive load(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileReader reader = new FileReader(filename);
        Directive dir = yaml.loadAs(reader, Directive.class);
        reader.close();
        return dir;
    }

    @Override
    public String toString(){
        return "("+Integer.toString(priority)+"): "+request;
    }
    
    public String getName(){
        return "("+Integer.toString(priority)+"): "+request;
    }
    
    public void setName(){
        //not allowed
    }
    /**
     * @return the priority
     */
    public int getPriority() {
        return priority;
    }

    /**
     * @param priority the priority to set
     */
    public void setPriority(int priority) {
        this.priority = priority;
    }

    /**
     * @return the request
     */
    public String getRequest() {
        return request;
    }

    /**
     * @param request the request to set
     */
    public void setRequest(String request) {
        this.request = request;
    }
    
    
    
}
